
/*
 * RW_lock.h
 *
 *  Created on: Dec 18, 2014
 *      Author: Uzi
 */

#ifndef RW_LOCK_H_
#define RW_LOCK_H_

#include <pthread.h>

typedef struct rwlock_t RWLock;

struct rwlock_t
{
	pthread_mutex_t mutex;

	pthread_cond_t writers_waiting;
	pthread_cond_t readers_waiting;

	unsigned int readers;
	unsigned int writers;
};

int rwlock_init(RWLock* lock);		//initialize

void wrlock(RWLock* lock);			//write lock

void rlock(RWLock* lock);			//read lock

void wrunlock(RWLock* lock);		//write unlock

void runlock(RWLock* lock);			//read unlock

void rwlock_destroy(RWLock* lock);	//destroy lock



#endif /* RW_LOCK_H_ */
